<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>用户总数</span>
            </div>
          </template>
          <div class="card-body">
            <div class="number">{{ statistics.userCount }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>角色总数</span>
            </div>
          </template>
          <div class="card-body">
            <div class="number">{{ statistics.roleCount }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>菜单总数</span>
            </div>
          </template>
          <div class="card-body">
            <div class="number">{{ statistics.menuCount }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>在线用户</span>
            </div>
          </template>
          <div class="card-body">
            <div class="number">{{ statistics.onlineCount }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { request } from '@/utils/request'

const statistics = ref({
  userCount: 0,
  roleCount: 0,
  menuCount: 0,
  onlineCount: 0
})

const getStatistics = async () => {
  try {
    const data = await request('/api/dashboard/statistics')
    if (data.code === 200) {
      statistics.value = data.data
    }
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
}

onMounted(() => {
  getStatistics()
})
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-body {
  text-align: center;
  padding: 20px 0;
}
.number {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
}
</style> 